use actix_web::web::{self};

use crate::handler::control_core;
use crate::handler::device;
use crate::handler::modules;
use crate::handler::sd;
use crate::handler::topic;
use crate::handler::user;

// sd
pub fn sd_router(cfg: &mut web::ServiceConfig) {
    cfg.service(
        web::scope("/sd")
            .route("/health_check", web::get().to(sd::health_check))
            .route("/cpu_check", web::get().to(sd::cpu_check))
            .route("/disk_check", web::get().to(sd::disk_check)),
    );
}

// user
pub fn user_router(cfg: &mut web::ServiceConfig) {
    cfg.service(
        web::scope("/user")
            .route("/create", web::post().to(user::create))
            .route("/edit", web::post().to(user::edit))
            .route("/delete/{id}", web::get().to(user::delete))
            .route("/detail/{id}", web::get().to(user::detail))
            .route("/get_name/{id}", web::get().to(user::get_user_name))
            .route("/list", web::get().to(user::list)),
    );
}

// topic
pub fn topic_router(cfg: &mut web::ServiceConfig) {
    cfg.service(
        web::scope("/topic")
            .route("/create", web::post().to(topic::create))
            .route("/edit", web::post().to(topic::edit))
            .route("/delete/{id}", web::get().to(topic::delete))
            .route("/detail/{id}", web::get().to(topic::detail))
            .route("/list", web::get().to(topic::list)),
    );
}

// device
pub fn device_router(cfg: &mut web::ServiceConfig) {
    cfg.service(
        web::scope("/device")
            .route("/create", web::post().to(device::create))
            .route("/edit", web::post().to(device::edit))
            .route("/delete/{id}", web::get().to(device::delete))
            .route("/detail/{id}", web::get().to(device::detail))
            .route("/list", web::get().to(device::get_device_list_handler)),
    );
}

// control core
pub fn control_core_router(cfg: &mut web::ServiceConfig) {
    cfg.service(
        web::scope("/control_core")
            .route("/create", web::post().to(control_core::create))
            .route("/edit", web::post().to(control_core::edit))
            .route("/delete/{id}", web::get().to(control_core::delete))
            .route("/detail/{id}", web::get().to(control_core::detail))
            .route("/list", web::get().to(control_core::list)),
    );
}

// Modules
pub fn modules_router(cfg: &mut web::ServiceConfig) {
    cfg.service(
        web::scope("/modules")
            .route("/create", web::post().to(modules::create))
            .route("/edit", web::post().to(modules::edit))
            .route("/list", web::get().to(modules::list))
            .route("/detail/{id}", web::get().to(modules::detail))
            .route("/delete/{id}", web::get().to(control_core::delete)),
    );
}
